package com.laizhenghua.share.rule.api.factory;

import com.laizhenghua.share.common.core.domain.R;
import com.laizhenghua.share.rule.api.RemoteRuleService;
import com.laizhenghua.share.rule.api.domain.entity.FeeRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * TODO
 *
 * @Description
 * @Author laizh
 * @Date 2025/10/15 21:44
 **/
@Component
public class RemoteRuleServiceFallbackFactory implements FallbackFactory<RemoteRuleService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteRuleServiceFallbackFactory.class);
    @Override
    public RemoteRuleService create(Throwable cause) {
        log.error("规则服务调用失败: {}", cause.getMessage());
        return new RemoteRuleService() {
            @Override
            public R<List<FeeRule>> list(List<Long> ids) {
                return R.fail("查询失败，请稍后重试！");
            }

            @Override
            public R<FeeRule> detail(Long id) {
                return R.fail("查询失败，请稍后重试！");
            }
        };
    }
}
